package fishBids.group3;



import jade.content.lang.Codec;
import jade.content.lang.sl.SLCodec;
import jade.content.onto.Ontology;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.ParallelBehaviour;
import jade.core.behaviours.SequentialBehaviour;
import fishBids.group3.behaviour.bidder.AuctionOverBidderBehaviour;
import fishBids.group3.behaviour.bidder.PriceVariatedBidderBehaviour;
import fishBids.group3.behaviour.bidder.RegisterBidderBehaviour;
import fishBids.group3.behaviour.common.FindTypeBehaviour;
import fishBids.group3.common.Constants;






/**

 * This agent has the following functionality: 

 * <ul>

 * <li> It register itself in the DF

 * <li> Asks the DF the name of new "painter" agents

 * <li> If there is any, it ask this agent for a service estimation;

 *      if not, waits and try it again later

 * <li> Waits for an answer to the request

 * <li> If the estimation provided is the best one among the received in a minute time,

 *      it sends an accept message to the painter; if not, sends one of rejection

 * </ul>

 * @author Gabriel & Mai, UPM

 * @version $Date: 2009/04/01 13:36:23 $ $Revision: 1.1 $

 **/





public class Bidder3 extends Agent {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6178595839409587169L;
	private Codec codec = new SLCodec(); 
	private Ontology ontology = es.upm.agents.ontology.Fish_BidsOntology.getInstance(); 
	private final AID auctioneerID = new AID();
	private final AID bankID = new AID();
	private final AID marketID = new AID();

	protected void setup()
	{

		System.out.println("bidder3: enters into the system");

		this.getContentManager().registerLanguage(codec); 
		this.getContentManager().registerOntology(ontology);		

//		BEHAVIOURS ****************************************************************
		//TODO read the number of milliseconds to wait for searching
		ParallelBehaviour FindBehaviour = new ParallelBehaviour();
		FindBehaviour.addSubBehaviour(new FindTypeBehaviour( Constants.AUCTIONEER,this,auctioneerID,5000));
		FindBehaviour.addSubBehaviour(new FindTypeBehaviour( Constants.MARKET,this,marketID,5000));
		FindBehaviour.addSubBehaviour(new FindTypeBehaviour( Constants.BANK,this,bankID,5000));
		
		SequentialBehaviour sq = new SequentialBehaviour(this);
		sq.addSubBehaviour(FindBehaviour);
		sq.addSubBehaviour(new RegisterBidderBehaviour(codec,ontology,auctioneerID,this));		
		sq.addSubBehaviour(new PriceVariatedBidderBehaviour(this, marketID, bankID) );
		addBehaviour(sq);
		addBehaviour(new AuctionOverBidderBehaviour(this) );
		
	}



	public Codec getCodec() {
		return codec;
	}



	public void setCodec(Codec codec) {
		this.codec = codec;
	}



	public Ontology getOntology() {
		return ontology;
	}



	public void setOntology(Ontology ontology) {
		this.ontology = ontology;
	}



	public AID getAuctioneerID() {
		return auctioneerID;
	}

	

}

